#!/usr/bin/env python
# -*- coding: utf-8 -*-

def exclude_context(*urls):
    """
    Запрещает запуск функции при совпадении URL
    exact - точное совпадение
    """
    def decorator(funct):
        def wrapper(request, exact=False, *args, **kwargs):
            for url in urls:
                if (exact and request.path_info == url) or (not exact and request.path_info.startswith(url)):
                    return {}
            else:
                return funct(request, *args, **kwargs)
        return wrapper
    return decorator


def filter_context(*urls):
    """
    Разрешает запуск функции при совпадении URL
    exact - точное совпадение
    """
    def decorator(funct):
        def wrapper(request, exact=False, *args, **kwargs):
            for url in urls:
                if (exact and request.path_info == url) or (not exact and request.path_info.startswith(url)):
                    return funct(request, *args, **kwargs)
            else:
                return {}
        return wrapper
    return decorator